<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
		<title>注册</title>
		<link rel="stylesheet" href="__PUBLIC__/css/weui.min.css" />
		<link rel="stylesheet" href="__PUBLIC__/css/example.css" />
		<script src="__PUBLIC__/js/zepto.min.js"></script>
		<script src="__PUBLIC__/js/jquery-weui.js"></script>
		<script src="__PUBLIC__/js/jquery.min.js"></script>
		<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	</head>
	<body>
		<div class="container js_container">
			<!--<div class="page">-->
			<div class="hd">
				<h1 class="page_title">平台注册</h1>
			</div>
			<div class="bd">
				<div class="weui_cells_title">请输入正确注册信息</div>
				<div class="weui_cells weui_cells_form">
					<div class="weui_cell">
						<div class="weui_cell_hd">
							<label class="weui_label">姓名</label>
						</div>
						<div class="weui_cell_bd weui_cell_primary">
							
							<input class="weui_input" id="name" type="text" maxlength="6" placeholder="请输入姓名" required="required" />
						</div>
					</div>
					<div class="weui_cell">
						<div class="weui_cell_hd">
							<label class="weui_label">学号</label>
						</div>
						<div class="weui_cell_bd weui_cell_primary">
							<input class="weui_input" id="number" type="number" maxlength="10" placeholder="请输入学号" required="required" />
						</div>
					</div>
					<div class="weui_cell ">
						<div class="weui_cell_hd">
							<label class="weui_label">班级</label>
						</div>
						<div class="weui_cell_bd weui_cell_primary">
							<select class="weui_select_apply" id="banji1">
								<option value="null" disabled="disabled">----</option>
								<foreach name="banji" item="banji">
									<option value="{$banji.class}">{$banji.class}</option>	
								</foreach>
								<option value="otherclass">其他班级</option>
							</select>
						</div>
					</div>
				</div>
				<div class="weui_cells_title" id="otherClassAreaTitle" style="display: none;">请正确手动填写班级(示例：国商1401)</div>
				<div class="weui_cells weui_cells_form">
					<div class="weui_cell" id="otherClassAreaInput" style="display: none;">
						<div class="weui_cell_hd"><label class="weui_label">班级</label></div>
						<div class="weui_cell_bd weui_cell_primary">
							<input class="weui_input" id="otherClassValue" type="text" maxlength="6" value="" required="required" />
						</div>
					</div>
				</div>
				<div class="weui_cells_title">请输入密码</div>
				<div class="weui_cells weui_cells_form">
					<div class="weui_cell">
						<div class="weui_cell_hd">
							<label class="weui_label">密码</label>
						</div>
						<div class="weui_cell_bd weui_cell_primary">
							<input class="weui_input" type="password" id="password" placeholder="请输入密码" maxlength="12" required="required" />
						</div>
					</div>
				</div>
				<div class="weui_cells_title">请重新输入密码</div>
				<div class="weui_cells weui_cells_form">
					<div class="weui_cell">
						<div class="weui_cell_hd">
							<label class="weui_label">密码</label>
						</div>
						<div class="weui_cell_bd weui_cell_primary">
							<input class="weui_input" id="password_again" type="password" placeholder="请重新输入密码" maxlength="12" required="required" />
						</div>
					</div>
				</div>

				<div class="weui_btn_area">
					<a href="javascript:;" class="weui_btn weui_btn_primary" id="showToast">确定</a>
				</div>
				<div id="toast1" style="display: none;">
					<div class="weui_mask_transparent"></div>
        			<div class="weui_toast">
            		<i class="weui_icon_toast"></i>
            		<p class="weui_toast_content">注册成功</p>
        			</div>
				</div>
			</div>
		</div>
		<script type="text/javascript">
			$("select").change(function(e){
				if($(this).val() == "otherclass"){
					$("#otherClassAreaTitle").show();
					$("#otherClassAreaInput").show();	
				}else{
					$("#otherClassAreaTitle").hide();
					$("#otherClassAreaInput").hide();
				}
			});
			
			$("#showToast").click(function(event){
    			var openId = "{$openId}";
                var name = $("#name").val();
        		var number = $("#number").val();
        		var banji = $("#banji1 option:selected").val();
        		if(banji == "otherclass")
        			var banji = $("#otherClassValue").val();
        		var password = $("#password").val();
        		var password_again = $("#password_again").val();
          		//作一个简单的判断
          		if(openId == ""){
          			alert('请在微信端注册');
          			return false;
          		}
    			if(name == "" || number == "" || password == "" || password_again == "" || banji == ""){
    				alert('注册信息不能为空');
    				return false;
    			}
    			
    			if(number.length != 10){
    					alert('学号必须是10位数');
    	 			return false;
    	  		}
    	  		if(password != password_again){
    	 			alert('两次输入的密码不一样！');
    	  			return false;
     	  		}
    			var data = {
    				openId:"{$openId}",
    				name: name,
    				number: number,
    				class :banji,
    				password : password
    			};
				$.ajax({
//                  cache:false,
                    type:"POST",
					//async:false,
					//contentType:
                    url:"{:U('Index/handleRegister')}",
//                  dataType:"json",
                    data: data,
                    timeout:30000,
                    error:function(){                      
						alert('注册失败，请稍候再试');
                    },
                    success:function(){
							
						//然后显示成功前端
							var $toast = $('#toast1');
		                    if ($toast.css('display') != 'none') {
		                        return;
		                    }
		                    $toast.show();
		                    setTimeout(function () {
		                        $toast.hide();
		                    }, 5000);
		                    wx.closeWindow();
	                }
                });

	        });
		</script>
	</body>
</html>